package cn.edu.scau.cmi.zhangmingxing.client;

import cn.edu.scau.cmi.zhangmingxing.singleton.Marsahal;
import cn.edu.scau.cmi.zhangmingxing.singleton.President;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class SingletonClient extends Application {
	@Override
	public void start(Stage primaryStage) {
		primaryStage.setTitle("Chairman");
		TextField myTextField = new TextField();
		myTextField.setLayoutX(10);
		Group root = new Group();
		Group hbox = new Group();
		Group group = new Group();
		TextArea area = new TextArea(); // 创建一个多行输入框
		// 设置多行输入框能否编辑

		area.setLayoutX(10);
		area.setLayoutY(45);
		area.setMaxHeight(240);
		area.setMaxWidth(550);
		area.setEditable(false);
		Button btn = new Button();
		Button btn2 = new Button();
		btn.setLayoutX(230);
		btn2.setLayoutX(400);
		btn.setText("Singleton pattarn");
		btn2.setText("Multiple case mode");
		Text text = new Text(10, 45, null);
		btn.setOnAction(new EventHandler<ActionEvent>() {
			@Override
			public void handle(ActionEvent event) {
				String str = new String();
				str = myTextField.getText();
				President president = President.getInstance(str);
				area.appendText(president.getname() + "@" + president.getnum() + '\n');

			}
		});
		btn2.setOnAction(new EventHandler<ActionEvent>() {
			public void handle(ActionEvent event) {
				String str = new String();
				str = myTextField.getText();
				Marsahal president = Marsahal.getInstance(str);
				if (president == null)
					area.appendText("There are ten presidents.Can't create more!\n");
				else
					area.appendText(president.getname() + "@" + president.getnum() + '\n');
			}
		});

		group.getChildren().add(area);
		group.getChildren().add(btn2);
		hbox.getChildren().addAll(myTextField, btn, text);
		root.getChildren().addAll(group, hbox);

		Scene scene = new Scene(root, 600, 300, Color.rgb(0, 0, 0, 0));
		primaryStage.setScene(scene);
		primaryStage.show();
	}

	public static void main(String[] args) {
		launch(args);
	}
}